<template>
  <div>
    <AplidForm
      ref="formRef"
      v-bind="ExtendFormConfig"
      v-model="formModel"
      @submit="onSubmit">
    </AplidForm>
  </div>
</template>

<script setup lang="ts">
import { ExtendFormConfig } from '@/views/datacenter/basicData/serviceFacility/config'
// import { getAreaObj } from '@/utils/util'
import { useOperate } from '@/views/datacenter/hooks/useConfig'
const { getValue } = useOperate(3)
import { cloneDeep } from 'lodash-es'
import { useCommonStore } from '@/stores/common'
const { setTempParams } = useCommonStore()
// dpServiceFacilityObject
// dpFacilityEquipmentList
// dpOperateRecordList
// dpSenileProductsList
// dpServiceFacilityExtend
// dpServiceFacilityOther
const rowData: any = inject('nowRowData')
let ExtendMod = rowData.value?.data?.dpServiceFacilityExtend
let baseExtendData = rowData.value?.baseData?.dpServiceFacilityExtend || {}
// let baseContactData = rowData.value?.baseData?.dpServiceObjectContacts || []
// let baseMaterData = rowData.value?.baseData?.dpServiceObjectMaterials || []

const emit = defineEmits(['submit'])
// const contactData = rowData.value?.data?.dpServiceObjectContacts || []

const formModel = ref({
  ...cloneDeep(ExtendMod),
})
const formRef = ref(null)
const onSubmit = (form, done) => {
  const { tempNowObj } = storeToRefs(useCommonStore())
  console.log('这个是个啥', tempNowObj)
  const params = {
      ...form,
      soleValue: tempNowObj.value.name,
      code:2003
  }
  console.log('处理',params,rowData)
   // 变更字段
   let changeColumnsBase = ExtendFormConfig.column.filter(
    (item) => item.changeField
  )
   // 处理变更数据
   let changeData = []
  changeColumnsBase.map((item) => {
    const tempBefore = baseExtendData[item.prop]
    const tempAfter = params[item.prop]
    if (tempBefore != tempAfter) {
      changeData.push({
        label: item.label,
        before: getValue(tempBefore, item),
        after: getValue(tempAfter, item)
      })
    }
  })
  console.log('搞定',changeData)
  const changeObj = {
    data: changeData,
    dataChangeContentList: [
      {
        changeBefore: {
          ...baseExtendData,
          code: undefined
        },
        changeAfter: {
          ...params,
          code: undefined
        },
        changeData: {
          ...params,
          code:2003
        },
        changeType:'养老服务设施拓展表',
        code: 2003
      },
    ],
  }
  setTempParams({
    name: params.soleValue,
    nowChange: changeObj
  })
  emit('submit', changeObj)
  done()
}

const onSave = () => {
  formRef.value!.onSubmit()
}
defineExpose({
  onSave
})
</script>

<style scoped></style>
